home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / niftp / qn2mm_send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-28  |  8.0 KB  |  272 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *
  16.  *
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /*                  SEND FROM NIFTP TO SUBMIT                           */
  36. /*                                                                      */
  37. /*      Adapted from ph2mm_send.c                                       */
  38. /*                                                                      */
  39. /*      Steve Kille     August 1982                                     */
  40. /*                                                                      */
  41. /*      Note that for now, this module only handles one message at      */
  42. /*      a time.  The overhead associated with Scanning a directory      */
  43. /*      is not worthwhile.  Eventually the NIFTP may pass pointers      */
  44. /*      too multiple files                                              */
  45.  
  46. /*
  47.  * Mar 83  Steve Kille  Adapt for new MMDF
  48.  *                      Changes to remove MMDF dependancies freom NIFTP
  49.  */
  50.  
  51. #include "ch.h"
  52. #include "phs.h"
  53.  
  54. extern struct ll_struct   *logptr;
  55.  
  56. extern Chan *curchan;
  57.  
  58. LOCVAR int qn_gotone;
  59.  
  60. qn2mm_send (fname, TSname)
  61.                 /* Send message(s) to submit            */
  62.     char fname[];               /* name of message file                 */
  63.     char TSname[];              /* TS name (calling address) of source  */
  64.                 /* host - to be translated to host name */
  65. {
  66.     short     result;
  67.     char    info[LINESIZE];
  68.     char    sender[LINESIZE];
  69.     struct rp_bufstruct thereply;
  70.     int len;
  71.  
  72. #ifdef DEBUG
  73.     ll_log (logptr, LLOGPTR, "qn2mm_send");
  74. #endif
  75.  
  76.     if (rp_isbad (result = qn_pkinit ()))
  77.     return (result);
  78.  
  79.     if (rp_isbad (result = mm_sbinit ()))
  80.     return (result);
  81.  
  82.  
  83.     if (rp_gval (result = qn_rinit (fname, TSname, info, sender)) != RP_OK){
  84.     if(rp_gval(result) != RP_FIO)
  85.         qn_rtend (sender, fname, RP_NO);    /* this closes the file */
  86.                         /* but does not */
  87.                         /* delete the message */
  88.     return(result);
  89.     }
  90.     /* 
  91.      * For now we only go through this loop
  92.      * once - multiple submissions later perhaps (but I doubt it)
  93.      */
  94.  
  95.     phs_note (curchan, PHS_RESTRT);
  96.  
  97.     strcat (info, "v");
  98.     if (rp_isbad (result = mm_winit (curchan -> ch_name, info, sender)))
  99.     return (result);      /* ready to process a message         */
  100.  
  101.     if (rp_isbad (result = mm_rrply (&thereply, &len)))
  102.     return (result);      /* how did remote like it?            */
  103.  
  104.     switch (rp_gbval (thereply.rp_val))
  105.     {              /* was source acceptable?            */
  106.     case RP_BNO:
  107.         case RP_BTNO:
  108.         return (thereply.rp_val);
  109.     }
  110.  
  111.     if (rp_isbad (result = qn2mm_admng ()))
  112.     {
  113.     qn_rtend (sender, fname, result);
  114.     return (result);
  115.     }
  116.  
  117.     if (!qn_gotone)        /* stop here if no good addresses     */
  118.                 /* send the address list              */
  119.     {
  120.     if (sender [0] == '\0')
  121.     {
  122.         ll_log (logptr, LLOGTMP,  "Filewith no valid addresseses and no return adr");
  123.         qn_rtend (sender, fname, RP_NDEL);
  124.         return (RP_NDEL);
  125.     }
  126.     return (qn_rtend (sender,  fname, RP_OK));
  127.     }
  128.  
  129.                 /* send the message text              */
  130.     if (rp_isbad (result = qn2mm_txmng (sender, fname)))
  131.     {
  132.     qn_rtend (sender, fname, result);
  133.     return (result);
  134.     }
  135.  
  136. #ifdef DEBUG
  137.     ll_log (logptr, LLOGBTR, "done with submission");
  138. #endif
  139.  
  140.     phs_note (curchan, PHS_REEND);
  141.  
  142.     if (rp_gval (result) == RP_DONE)
  143.     return (RP_OK);
  144.     return (result);
  145. }
  146. /* */
  147.  
  148. LOCFUN
  149.     qn2mm_admng ()             /* send address list                  */
  150. {
  151.     struct rp_bufstruct thereply;
  152.     int       len;
  153.     short     result;
  154.     char    host[LINESIZE];
  155.     char    adr[LINESIZE];
  156.  
  157.     qn_gotone = FALSE;
  158.     FOREVER                       /* iterate thru list                    */
  159.     {                             /* we already have and adr              */
  160.     result = qn_radr (host, adr);
  161.     if (rp_isbad (result))
  162.         return (result);      /* get address from NIFTP file        */
  163.     if (rp_gval (result) == RP_DONE)
  164.         break;                /* end of address list                */
  165.  
  166. #ifdef DEBUG
  167.     ll_log (logptr, LLOGFTR, "'%s'@'%s'", adr, host);
  168. #endif
  169.  
  170.     if (rp_isbad (result = mm_wadr (host, adr)))
  171.         return (result);      /* give to remote site                */
  172.  
  173.     if (rp_isbad (result = mm_rrply (&thereply, &len)))
  174.         return (result);      /* how did remote like it?            */
  175.  
  176.     switch (rp_gval (thereply.rp_val))
  177.                   /* was address acceptable?            */
  178.     {
  179.         case RP_AOK:          /* address ok, text not yet sent      */
  180.         case RP_DOK:
  181.         qn_wrply (&thereply, adr, host);
  182.         qn_gotone = TRUE;
  183.         break;
  184.  
  185.         case RP_NO:           /* remaining acceptible responses     */
  186.         thereply.rp_val = RP_NDEL;
  187.         case RP_USER:         /* unknown user                       */
  188.         case RP_NDEL:
  189.         case RP_AGN:
  190.         case RP_NOOP:
  191.         case RP_NS:
  192.         qn_wrply (&thereply, adr, host);
  193.         break;
  194.  
  195.         default:              /* responses which force abort        */
  196.         qn_wrply (&thereply, adr, host);
  197.         ll_log (logptr, LLOGFAT,
  198.             "reply err (%s)'%s'",
  199.             rp_valstr (thereply.rp_val), thereply.rp_line);
  200.         if (rp_isbad (thereply.rp_val))
  201.             return (thereply.rp_val);
  202.         return (RP_RPLY);
  203.     }
  204.     }
  205.     if (rp_isbad (result = qn_raend ()))
  206.     return (result);        /* read end of address list            */
  207.                  /* sets fp to beginning of text       */
  208.  
  209.  
  210.     return (mm_waend ());        /* tell remote of address list end    */
  211. }
  212. /* */
  213.  
  214. LOCFUN
  215.     qn2mm_txmng (sender, fname) /* send message text                  */
  216.    char *sender;                /* Who sent the message - for error     */
  217.                 /* replies to go to                     */
  218.     char        *fname;         /* Name of file containing message      */
  219.                 /* needed to unlink message             */
  220. {
  221.     struct rp_bufstruct thereply;
  222.     int     len;
  223.     short   result;
  224.     char    buffer[BUFSIZ];
  225.  
  226. #ifdef DEBUG
  227.     ll_log (logptr, LLOGPTR, "doing text");
  228. #endif
  229.     len = sizeof(buffer);
  230.     while ((rp_gval (result = qn_rtxt (buffer, &len))) == RP_OK)
  231.     {
  232.     if (rp_isbad (result = mm_wtxt (buffer, len)))
  233.         return (result);
  234.     len = sizeof(buffer);
  235.     }
  236. #ifdef DEBUG
  237.     ll_log (logptr, LLOGBTR, "done sending");
  238. #endif
  239.  
  240.     if (rp_isbad (result))
  241.     return (result);          /* problem with transmission          */
  242.     if (rp_gval (result) != RP_DONE)
  243.     return (RP_RPLY);         /* protocol error in reply code       */
  244.  
  245.     if (rp_isbad (result = mm_wtend ()))
  246.     return (result);          /* flag end of message                */
  247.  
  248.     if (rp_isbad (result = mm_rrply (&thereply, &len)))
  249.     return (result);          /* problem getting reply?             */
  250. #ifdef DEBUG
  251.     ll_log (logptr, LLOGBTR, "got text reply");
  252. #endif
  253.  
  254.     switch (rp_gval (thereply.rp_val))
  255.     {                             /* was text acceptable?               */
  256.     case RP_OK:
  257.     case RP_MOK:              /* text was accepted                  */
  258.         break;
  259.  
  260.     default:                  /* responses which force abort        */
  261.         ll_log (logptr, LLOGFAT, "reply err (%s)'%s'",
  262.             rp_valstr (thereply.rp_val), thereply.rp_line);
  263.         return (thereply.rp_val);
  264.     }
  265.  
  266.                 /* sent it out, so clean up read        */
  267.     if (rp_isbad (result = qn_rtend (sender, fname, RP_OK)))
  268.     return (result);          /* flag end of message                */
  269.  
  270.     return (RP_OK);
  271. }
  272.